﻿<navigation:Page xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"  
           xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
           xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
           xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
           xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
           xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
           xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit"
            x:Class="PivotViewerBase.ColorSchemeDesigner"
           mc:Ignorable="d"
            xmlns:local="clr-namespace:PivotViewerBase"
             d:DesignWidth="640" d:DesignHeight="480"
           Title="ColorSchemeDesigner Page" Loaded="Page_Loaded_1" >
    <navigation:Page.Resources>
        <local:NamedColorValueConverter  x:Key="bgConv" />
        <local:ConvertItemToIndex x:Key="IndexConverter"/>
        <local:MVVM ForeGround="Lime" x:Key="MVVM" />
    </navigation:Page.Resources>
    <Viewbox MaxWidth="1024"  SizeChanged="Viewbox_SizeChanged_1" HorizontalAlignment="Left" VerticalAlignment="Top" Stretch="Uniform" >
        <StackPanel x:Name="LayoutRoot" HorizontalAlignment="Left" VerticalAlignment="Top">
            <StackPanel.Background>
                <LinearGradientBrush EndPoint="0.5,1" MappingMode="RelativeToBoundingBox" StartPoint="0.5,0">
                    <GradientStop Color="Black" Offset="0.778"/>
                    <GradientStop Color="#FFE7E8EC"/>
                </LinearGradientBrush>
            </StackPanel.Background>

            <!-- Top Buttons -->
            <Grid Height="24">
                <Grid.Background>
                    <LinearGradientBrush EndPoint="0.5,1" MappingMode="RelativeToBoundingBox" StartPoint="0.5,0">
                        <GradientStop Color="#FFFFFFFF" Offset="0.778"/>
                        <GradientStop Color="#FFAD3239"/>
                    </LinearGradientBrush>
                </Grid.Background>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition></ColumnDefinition>
                    <ColumnDefinition Width="2"></ColumnDefinition>
                    <ColumnDefinition></ColumnDefinition>
                </Grid.ColumnDefinitions>

                <StackPanel Orientation="Horizontal" Grid.Column="0" HorizontalAlignment="Left" >

                    <StackPanel Orientation="Horizontal">

                        <ToggleButton x:Name="btnCreateNewPallette" Width="18"  Height="18" Margin="5,0,0,0" VerticalAlignment="Center"  ClickMode="Press" Click="btnCreateNewPallette_Click" >
                            <Image Source="/PivotViewerBase;component/Images/New32.png" Width="14" Height="14" ToolTipService.ToolTip="Start New Pallette"  HorizontalAlignment="Center" VerticalAlignment="Center"/>
                        </ToggleButton>
                        <ToggleButton x:Name="btnSavePalletteFile" Width="18"  Height="18" Margin="5,0,0,0" VerticalAlignment="Center"  ClickMode="Press" Click="btnSavePalletteFile_Click" >
                            <Image Source="/PivotViewerBase;component/Images/Save32.png" Width="14" Height="14" ToolTipService.ToolTip="Save Current Pallette to a Pallette File" HorizontalAlignment="Center" VerticalAlignment="Center" />
                        </ToggleButton>
                        <ToggleButton x:Name="btnOpenPalletteFile" Width="18"  Height="18" Margin="5,0,0,0" VerticalAlignment="Center"  ClickMode="Press" Click="btnOpenPalletteFile_Click" >
                            <Image Source="/PivotViewerBase;component/Images/Open32.png" Width="14" Height="14" ToolTipService.ToolTip="Open Existibg Pallette" HorizontalAlignment="Center" VerticalAlignment="Center" />
                        </ToggleButton>
                        <ToggleButton x:Name="btnCopyPalletteColorsString" Width="18"  Height="18" Margin="5,0,0,0" VerticalAlignment="Center"  ClickMode="Press" ToolTipService.ToolTip="Copy Pallette String to Clipboard" Click="btnCopyPalletteColorsString_Click" >
                            <Image Source="/PivotViewerBase;component/Images/Copy.png" Width="14" Height="14" HorizontalAlignment="Center" VerticalAlignment="Center"/>
                        </ToggleButton>
                        <ToggleButton x:Name="btnImportPallette"  Width="18" Height="18" Margin="5,0,0,0" VerticalAlignment="Center"  ClickMode="Press" ToolTipService.ToolTip="Import Pallette from File" Click="btnImportPallette_Click_1" >
                            <Image Source="Images/Import.png" Width="14" Height="14" HorizontalAlignment="Center" VerticalAlignment="Center"/>
                        </ToggleButton>
                        <ToggleButton x:Name="btnExportPallette"  Width="18" Height="18" Margin="5,0,0,0" VerticalAlignment="Center"  ClickMode="Press" ToolTipService.ToolTip="Export Pallette to File" Click="btnExportPallette_Click_1" >
                            <Image Source="Images/Export.png" Width="14" Height="14" HorizontalAlignment="Center" VerticalAlignment="Center"/>
                        </ToggleButton>
                        <!--<Button HorizontalAlignment="Left" Height="18"  Margin="0,0,10,0" FontSize="8" Content=" Save... " ToolTipService.ToolTip="Save Current Pallette to a Pallette File"/>
                    <TextBlock Text="Select Pallette" Margin="10,0,2,0" FontSize="8" VerticalAlignment="Center"/>
                    <ComboBox FontSize="8" Height="18"  ToolTipService.ToolTip="List of Saved Pallette Files">

                    </ComboBox>
                    <Button Content="..." Height="18"  Margin="2,0,2,0" FontSize="8"  ToolTipService.ToolTip="Load Seleted Pallette"/>-->
                    </StackPanel>
                </StackPanel>
                <StackPanel x:Name="stkPalletteFileNames"  Orientation="Horizontal"  Grid.Column="0"  Grid.ColumnSpan="3"  Margin="50,0,15,0" HorizontalAlignment="Center" >
                    <TextBox x:Name="txtPalletteFileName" Text="New Pallette" Height="20" Width="200" FontSize="8" BorderBrush="Transparent" Background="Transparent" IsReadOnly="True" KeyDown="txtPalletteFileName_KeyDown"   />
                    <ToggleButton x:Name="btnSavePalletteFileToIsolatedStorage" Visibility="Collapsed" Width="18"  Height="18" Margin="5,0,0,0" VerticalAlignment="Center"  ClickMode="Press" Click="btnSavePalletteFileToIsolatedStorage_Click_1"  >
                        <Image Source="/PivotViewerBase;component/Images/Save32.png" Width="14" Height="14" ToolTipService.ToolTip="Save Current Pallette to a Pallette File" HorizontalAlignment="Center" VerticalAlignment="Center" />
                    </ToggleButton>
                    <Button x:Name="btnDeletePalletteFile"  HorizontalAlignment="Left" Height="18" Width="18" Margin="5,0,0,0" FontWeight="ExtraBold" FontSize="8" 
                            Content="x" ToolTipService.ToolTip="Delete Selected Pallette" Click="btnDletePalletteFile_Click_1"/>



                </StackPanel>
                <StackPanel HorizontalAlignment="Center" x:Name="stkPalletteList" Visibility="Collapsed" Orientation="Horizontal" Grid.Column="0"  Grid.ColumnSpan="3"  Margin="5,0,15,0" >
                    <ComboBox x:Name="cboPalletteFileNames" Width="200" Height="20" FontSize="8" BorderBrush="Transparent" Background="Transparent"   KeyDown="txtPalletteFileName_KeyDown" SelectionChanged="cboPalletteFileNames_SelectionChanged"  />
                </StackPanel>

            </Grid>

            <!-- Pallette Buttons -->
            <StackPanel Margin="5,5,0,0" Orientation="Horizontal" HorizontalAlignment="Center">
                <Button x:Name="btnAddForeGroundRow" Height="18" Width="18" Margin="0,0,0,0" FontWeight="ExtraBold" FontSize="8"
                        
                            ToolTipService.ToolTip="Add New Foreground Row" Click="btnAddForeGroundRow_Click">
                    <Grid>
                        <Path Stroke="Gray" StrokeThickness=".5" Fill="Transparent" >

                            <Path.Data>

                                <GeometryGroup >

                                    <EllipseGeometry Center="6,6" RadiusX="6" RadiusY="6" />


                                </GeometryGroup>

                            </Path.Data>

                        </Path>
                        <TextBlock Margin="3,0,0,0"  Text="+" />
                    </Grid>

                </Button>
                <Button x:Name="btnRemoveForeGroundRow" Height="18" Width="18" Margin="5,0,0,0" FontWeight="ExtraBold" FontSize="8" 
                        ToolTipService.ToolTip="Remove Selected Foreground Row" Click="btnRemoveForeGroundRow_Click">
                    <Grid>
                        <Path Stroke="Gray" StrokeThickness=".5" Fill="Transparent" >

                            <Path.Data>

                                <GeometryGroup >

                                    <EllipseGeometry Center="6,6" RadiusX="6" RadiusY="6" />


                                </GeometryGroup>

                            </Path.Data>

                        </Path>
                        <TextBlock Margin="3,0,0,0"  Text="x" />
                    </Grid>

                </Button>
                <Button x:Name="btnAddForeGroundRows" Height="18" Width="18" Margin="5,0,0,0" FontWeight="ExtraBold" FontSize="8" 
                        ToolTipService.ToolTip="Add Next New Foreground Rows" Click="btnAddForeGroundRows_Click_1">
                    <Grid>
                        <Path Stroke="Gray" StrokeThickness=".5" Fill="Transparent" >

                            <Path.Data>

                                <GeometryGroup >

                                    <EllipseGeometry Center="6,6" RadiusX="6" RadiusY="6" />


                                </GeometryGroup>

                            </Path.Data>

                        </Path>
                        <TextBlock Margin="3,2,0,2"  Text="*" />
                    </Grid>

                </Button>
                <Border BorderBrush="Gray" BorderThickness=".50" Width="18" Height="18" Margin="5,0,20,0"
                        ToolTipService.ToolTip="{Binding ElementName=ellipseForeground, Path=Tag}" 
                        MouseLeftButtonUp="Border_MouseLeftButtonUp_1">
                    <Grid>
                        <Ellipse x:Name="ellipseForeground" Width="12" Height="12" Margin="-1,-1,0,0"  
                            DataContext="{StaticResource MVVM}" Fill="{Binding ForeGround, Converter={StaticResource bgConv}}" 
                            ToolTipService.ToolTip="{Binding ForeGroundTitle}" Tag="{Binding ForeGroundTitle}"
                            HorizontalAlignment="Center" VerticalAlignment="Center" MouseLeftButtonUp="ellipseForeground_MouseLeftButtonUp" />
                        <Path Stroke="Gray" StrokeThickness=".5" Fill="Transparent" >

                            <Path.Data>

                                <GeometryGroup >

                                    <EllipseGeometry Center="8,8" RadiusX="6" RadiusY="6" />


                                </GeometryGroup>

                            </Path.Data>

                        </Path>
                    </Grid>
                </Border>
                <StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Margin="0,0,0,0">
                    <Button x:Name="btnAddNewBackgoundColumn" HorizontalAlignment="Left" Height="18" Width="18" Margin="0,0,0,0" FontWeight="ExtraBold" FontSize="8" 
                            Content="+" ToolTipService.ToolTip="Add New Backgound Column" Click="btnAddNewBackgoundColumn_Click" />
                    <Button x:Name="btnRemoveSelectedBackgoundColumn"  HorizontalAlignment="Left" Height="18" Width="18" Margin="5,0,0,0" FontWeight="ExtraBold" FontSize="8" 
                            Content="-" ToolTipService.ToolTip="Remove Selected Backgound Column" Click="btnRemoveSelectedBackgoundColumn_Click"/>
                    <Button x:Name="btnAddNewBackgoundColumns"  HorizontalAlignment="Left" Height="18" Width="18" Margin="5,0,0,0" FontWeight="ExtraBold" FontSize="8" 
                            Content="*" ToolTipService.ToolTip="Add Next New Backgound Columns" Click="btnAddNewBackgoundColumns_Click_1"/>
                    <Border BorderBrush="Gray" BorderThickness=".50" Width="18" Height="18" Margin="5,0,0,0">
                        <Border BorderBrush="Gray" BorderThickness=".50" Width="12" Height="12" Margin="-2,-2,0,0">
                            <Rectangle x:Name="rectangleBackground" Width="11" Height="11"   Margin="-2,-2,0,0"
                            DataContext="{StaticResource MVVM}" MouseLeftButtonUp="Rectangle_MouseLeftButtonUp_1"
                            ToolTipService.ToolTip="{Binding BackGroundTitle}" Tag="{Binding BackGroundTitle}"
                            Fill="{Binding BackGround, Converter={StaticResource bgConv}}" />
                        </Border>
                    </Border>

                </StackPanel>
            </StackPanel>

            <!-- Pallette Display & Editor -->
            <sdk:DataGrid x:Name="dataGrid1" Margin="5,1,0,0" HorizontalAlignment="Center"
                          Grid.ColumnSpan="2"  Grid.Column="0" HeadersVisibility="Row" 
                          RowHeight="18" LoadingRow="dataGrid1_LoadingRow">

                <sdk:DataGrid.RowHeaderStyle>
                    <Style TargetType="sdk:DataGridRowHeader">
                        <Setter Property="Content" Value="{Binding ElementName=dataGrid1,Path=.,Converter={StaticResource IndexConverter}}" />
                        <Setter Property="FontSize" Value="8" />
                    </Style>
                </sdk:DataGrid.RowHeaderStyle>
                <sdk:DataGrid.Columns>
                    <sdk:DataGridTemplateColumn CanUserSort="True" CanUserReorder="True" CellStyle="{x:Null}" CanUserResize="True" CellEditingTemplate="{x:Null}" ClipboardContentBinding="{x:Null}" CellTemplate="{x:Null}" DisplayIndex="-1" DragIndicatorStyle="{x:Null}" HeaderStyle="{x:Null}" Header="Fore↓" IsReadOnly="False" MaxWidth="Infinity" MinWidth="0" SortMemberPath="{x:Null}" Visibility="Visible" Width="Auto"/>
                    <sdk:DataGridTemplateColumn CanUserSort="True" CanUserReorder="True" CellStyle="{x:Null}" CanUserResize="True" CellEditingTemplate="{x:Null}" ClipboardContentBinding="{x:Null}" CellTemplate="{x:Null}" DisplayIndex="-1" DragIndicatorStyle="{x:Null}" HeaderStyle="{x:Null}" Header="Back→" IsReadOnly="False" MaxWidth="Infinity" MinWidth="0" SortMemberPath="{x:Null}" Visibility="Visible" Width="Auto"/>
                </sdk:DataGrid.Columns>

            </sdk:DataGrid>

            <!-- Pallette Color Selectors -->
            <Grid Margin="5">
                <Grid.RowDefinitions>
                    <RowDefinition Height="20" />
                    <RowDefinition Height="*"/>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition></ColumnDefinition>
                    <ColumnDefinition></ColumnDefinition>
                </Grid.ColumnDefinitions>

                <!--<toolkit:ShinyRedTheme Grid.Row="1"/>-->

                <!-- Foreground Color Picker -->
                <!--<toolkit:ExpressionDarkTheme />-->
                <TextBlock Text="Foreground Colors" Margin="4,8,0,0" FontSize="8" Foreground="White" />
                <ItemsControl Grid.Row="1" ItemsSource="{StaticResource NamedColorsList}" Height="240" Width="240"   Margin="4,0" >
                    <ItemsControl.ItemsPanel>
                        <ItemsPanelTemplate>
                            <toolkit:WrapPanel Orientation="Horizontal" Background="{Binding ElementName=rectangleBackground, Path=Fill}" />
                        </ItemsPanelTemplate>
                    </ItemsControl.ItemsPanel>
                    <ItemsControl.ItemTemplate>
                        <DataTemplate>

                            <Grid>
                                <!--<TextBlock Text="{Binding ColorName}" />-->
                                <Border BorderThickness=".25" BorderBrush="Black"/>
                                <Ellipse Tag="{Binding ColorName}"
                            ToolTipService.ToolTip="{Binding ColorName}" 
                            Fill="{Binding ColorValue,Converter={StaticResource bgConv}}" 
                            Margin="4" Height="12" Width="12" MouseLeftButtonUp="Ellipse_MouseLeftButtonUp_1"/>

                            </Grid>

                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                </ItemsControl>

                <!-- Background Color Picker -->
                <TextBlock Text="Background Colors" Grid.Column="1" Margin="10,8,0,0" FontSize="8"  Foreground="White"/>
                <ItemsControl 
             Grid.Row="1" Grid.Column="1" 
            ItemsSource="{StaticResource NamedColorsList}" 
            Margin="8,0,4,0"
            Height="240" Width="240" Background="Transparent">
                    <ItemsControl.ItemsPanel>
                        <ItemsPanelTemplate>
                            <toolkit:WrapPanel Orientation="Horizontal" />
                        </ItemsPanelTemplate>
                    </ItemsControl.ItemsPanel>
                    <ItemsControl.ItemTemplate>
                        <DataTemplate>

                            <Grid>
                                <!--<TextBlock Text="{Binding ColorName}" />-->
                                <Rectangle ToolTipService.ToolTip="{Binding ColorName}" Tag="{Binding ColorName}"
                        Fill="{Binding ColorValue,Converter={StaticResource bgConv}}" Margin="2" Height="16" Width="16" MouseLeftButtonUp="Rectangle_MouseLeftButtonUp_1" />
                                <Ellipse Fill="{Binding ElementName=ellipseForeground, Path=Fill}" Width ="6" Height="6" DataContextChanged="Ellipse_DataContextChanged_1" />
                            </Grid>

                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                </ItemsControl>

            </Grid>

        </StackPanel>
    </Viewbox>
</navigation:Page>
